cc.Class({
    extends: cc.Component,
    properties: {
        seadId: 0,
        nodeHead: {
            default: null,
            type: cc.Node
        },
        labCoin: {
            default: null,
            type: cc.Label
        },
        labName: {
            default: null,
            type: cc.Label
        },
        readyTip: {
            default: null,
            type: cc.Node
        }
    },
    onLoad: function () {
        Global.notificationCenter.on(Global.eventName.GAME_WAITTING_SHOWHEADDATA, this._refresh.bind(this), this),
            Global.notificationCenter.on(Global.eventName.GAME_SHOW_ISREADY, this.onShowReadyState.bind(this), this),
            Global.notificationCenter.on(Global.eventName.MSG_LEAVE, this.deleteLeaveUser.bind(this), this),
            this._players = Global.tableModel.getPlayers();
        for (var e = 0; e < this._players.length; e++) {
            var t = {
                seatId: this._players[e].seatId,
                state: this._players[e].state
            };
            this.onRefreshReadyState(t);
        }
        this.isInitHead = !1;
    },
    start: function () {
    },
    onDestroy: function () {
        Global.notificationCenter.offAll(this);
    },
    refresh: function () {
        var e = Global.tableModel.getPlayerModel(this.seadId);
        if (e) {
            var t = e.getPic(),
                n = Global.tableModel.getTableType() == Global.config.tableType.CREATE ? e.getFriScore() : e.getTableCoin();
            if (!this.isInitHead) {
                var o = e.getName();
                if (this.seadId == Global.config.SEAT_DOWN) Global.userProfile.setMyHeadSpf(this.nodeHead.getComponent("HeadController").spHead),
                    o = Global.userProfile.getUserName(); else {
                    var i = this.nodeHead.getComponent("HeadController");
                    i && i.bindData(t);
                }
                this.labName.node.parent.active = !0, this.labName.string = Global.utils.getFixString(o, 5),
                    this.isInitHead = !0;
            }
            this.labCoin.node.parent.active = !0, this.labCoin.string = Global.utils.exchangeToWan(n);
        }
    },
    _refresh: function () {
        this.refresh();
    },
    onShowReadyState: function (e) {
        var t = Global.tableModel.toLocalSeatIndex(e.seatId);
        this.seadId == t && (this.readyTip.active = !0);
    },
    onRefreshReadyState: function (e) {
        var t = Global.tableModel.toLocalSeatIndex(e.seatId);
        this.seadId == t && e.state == Global.config.playState.READY && (this.readyTip.active = !0);
    },
    deleteLeaveUser: function (e) {
        var t = Global.tableModel.toLocalSeatIndex(e.seatId);
        if (this.seadId == t && this.seadId !== Global.config.SEAT_DOWN) {
            var n = this.nodeHead.getComponent("HeadController");
            n && n.deleteData(), this.labCoin.node.parent.active = !1, this.labName.node.parent.active = !1,
                Global.tableModel.removePlayer(e), this.readyTip.active = !1, Global.notificationCenter.emit(Global.eventName.MSG_JUDGE_SEAT_FULL);
        }
    }
})
